package io.gitee.twoke.generator.spring;

import io.gitee.twoke.generator.engine.impl.cfg.TransactionContext;
import io.gitee.twoke.generator.engine.impl.cfg.TransactionContextFactory;
import io.gitee.twoke.generator.engine.impl.interceptor.CommandContext;
import org.springframework.transaction.PlatformTransactionManager;

public class SpringTransactionContextFactory implements TransactionContextFactory {

  protected PlatformTransactionManager transactionManager;
  protected Integer transactionSynchronizationAdapterOrder;

  public SpringTransactionContextFactory(PlatformTransactionManager transactionManager) {
    this(transactionManager, null);
  }

  public SpringTransactionContextFactory(PlatformTransactionManager transactionManager, Integer transactionSynchronizationAdapterOrder) {
    this.transactionManager = transactionManager;
    this.transactionSynchronizationAdapterOrder = transactionSynchronizationAdapterOrder;
  }

  public TransactionContext openTransactionContext(CommandContext commandContext) {
    return new SpringTransactionContext(transactionManager, commandContext, transactionSynchronizationAdapterOrder);
  }

}